package com.sooth.micro.page.service;

import cn.hutool.core.collection.CollUtil;
import com.dream.boot.impl.ServiceImpl;
import com.sooth.micro.page.mapper.MicroPageMapper;
import com.sooth.micro.page.view.MicroAppPageVo;
import com.sooth.micro.page.view.MicroPageBo;
import com.sooth.micro.page.view.MicroPageVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Service
public class MicroPageServiceImpl extends ServiceImpl<MicroPageVo, MicroPageBo> implements IMicroPageService {

    private final MicroPageMapper microPageMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(MicroAppPageVo appPageVo) {
        microPageMapper.deleteByAppId(appPageVo.getAppId());
        List<MicroPageBo> pageList = appPageVo.getPageList();
        if (CollUtil.isNotEmpty(pageList)) {
            batchInsert(pageList);
        }
    }

    @Override
    public Long getAppId(Long id) {
        return microPageMapper.getAppId(id);
    }
}
